package com.xcloud.component.db;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;

public interface BaseService<E,M> extends IService<E> {
    default M getMapper() {
        return (M)getBaseMapper();
     }

    default List<E> listByOneField(SFunction<E,?> column, Object val) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.listByOneField(column,val);
    }

    default Page<E> pageByOneField(Page page, SFunction<E, ?> column, Object val) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.pageByOneField(page,column,val);
        }

    default E getByOneField(SFunction<E, ?> column, Object val) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.getByOneField(column,val);
    }

    default int deleteByOneField(SFunction<E, ?> column, Object val) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.deleteByOneField(column,val);
    }

    default List<E> listByTwoField(SFunction<E, ?> column1, Object val1, SFunction<E, ?> column2, Object val2) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.listByTwoField(column1,val1,column2,val2);
    }

    default Page<E> pageByTwoField(Page page, SFunction<E, ?> column1, Object val1, SFunction<E, ?> column2, Object val2) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.pageByTwoField(page,column1,val1,column2,val2);
    }

    default E getByTwoField(SFunction<E, ?> column1, Object val1, SFunction<E, ?> column2, Object val2) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.getByTwoField(column1,val1,column2,val2);
    }

    default int deleteByTwoField(SFunction<E, ?> column1, Object val1, SFunction<E, ?> column2, Object val2) {
        ExtMapper<E> extMapper = (ExtMapper) getBaseMapper();
        return extMapper.deleteByTwoField(column1,val1,column2,val2);
    }
}
